package com.study.hotreloadsample;

import android.app.Application;
import android.os.Build;
import android.util.Log;

import com.study.hotreloadsample.hotReload.HotReloadUtil;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 作者： zjf 10/10/20 3:23 PM
 * 参考：
 * 描述：
 */
public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        init();
    }

    private void init() {
        //把assets中的dex文件拷贝到私有的files文件目录
        File dexFile = new File(getFilesDir(), "reload.dex");
        try {
            try (InputStream inputStream = getAssets().open("out.dex")) {
                try (FileOutputStream outputStream = new FileOutputStream(dexFile)) {
                    byte[] buf = new byte[1024];
                    int len;
                    while ((len = inputStream.read(buf)) > 0) {
                        outputStream.write(buf, 0, len);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        Log.e("文件目录", dexFile.getAbsolutePath());
        Log.e("Build version", String.valueOf(Build.VERSION.SDK_INT));
        HotReloadUtil.init(this, dexFile);
    }
}
